package org.abratuhi.kvngroupware.network;

import org.jdom.Element;

public class BasicRequestMessageProceeder extends AbstractRequestMessageProceeder{
	
	public BasicRequestMessageProceeder(){
		
	}

	@Override
	public void proceedMessage(Client client, Message message) {
		System.out.println("BASIC_REQUEST_MESSAGE_PROCEEDER [recv]: "+message.toString()); // TODO: logger
		//Element from = message.getRoot().getChild("from");
		//Element to = message.getRoot().getChild("to");
		Element request = message.getRoot().getChild("request");
		String type = request.getAttributeValue("type");
		String action = request.getAttributeValue("action");
		
		if(type.equals("user") && action.equals("login")){
			client.setId(request.getChild("user").getAttributeValue("id"));
			client.register();
			System.out.println("BASIC_REQUEST_MESSAGE_PROCEEDER [register]: "+client.getId()); // TODO: logger
		}
		else if(type.equals("user") && action.equals("logout")){
			client.unregister();
			System.out.println("BASIC_REQUEST_MESSAGE_PROCEEDER [unregister]: "+client.getId()); // TODO: logger
		}
		//else{
		//	System.out.println(r.getAttributeValue("type") + " : " + r.getAttributeValue("action"));
		//}
	}

}
